Analytics Integration¶
CMS Integration¶
When a new article is published you can use the following API, to push it to piStats:
API Endpoint: http://events.pi-stats.com/content
{
"articleId" : ,
"language" : ,
"format" : ,
"thumbnail" : ,
"propertyId" : ,
"title" : ,
"url" : ,
"publicationDate" : ,
"authorName" : ,
"authorEmail" : ,
"authorDesignation" : ,
"authorImage" : ,
"categoryList" : [],
"sectionList" : [],
"editorList" : [],
"tagList" : [],
"body" : '',
"description" : ''
}
Field | Description | Datatype | Example |
---|---|---|---|
articleId | Unique id of the article | string | ‘c059D45’ |
language | Article Language | string | ‘english’, ‘en’ , ‘hindi’ |
format | Article format/type | string | ‘video’, ‘gallery’ |
thumbnail | Article thumbnail URL article | string | ‘http://imageurl’ |
propertyId | Property id | string | ‘client-live’ |
title | Article headline | string | ‘Election Results Live’ |
url | Article URL | string | ‘http://article.com’ |
publicationDate | Article publication date (UTC format) | date | ‘2017-05-15T12:09:09Z’ |
loginAuthorName | Author name | string | ‘Author Name’ |
authorEmail | Author email | string | ‘author@greatnews.com’ |
authorDesignation | Author designation | string | ‘editor’ |
authorImage | Author image url | string | ‘http://authorimageur’ |
categoryList | Article category list | list of string | [‘India’, ‘Business’] |
sectionList | Article section list | list of string | [‘video’, ‘gallery’] |
editorList | Article author list (multiple contributors) | list of string | [‘author1’, ‘author2’] |
body | Article body | string | ‘article body’ |
description | A short description of Article | string | ‘Election Results Live’ |
Javascript¶
Tracking events on web is a two step process:
Include Javascript library: To start tracking the analytics events, please include the JavaScript library on all the pages which should be tracked. The library would be loaded asynchronously with the given code snippet.
- JavaScript Library: pistats-lib-analytics.pi-stats.com/library.min.js
- init( <property-id> , true ) : This method needs to be called on every page.
- <property-id>: pass property-id as the first argument
- <true/false>: pass ‘true’ to enable automatic tracking for the page. ‘false’ to track manually.
- load(): If ‘false’ is passed in the ‘init’ method, then load() method needs to be called manually on each page after init method has been called.
Expose variables on page: Expose the following variables on each page. piStats would automatically pick up these variables.
- ‘site_lang’ : Language of the site, for example ‘hindi’, ’tamil’ etc.
- ‘site_story_id’: Unique article id which is being read. On pages where article id might not be available, a unique id can be returned. For example, on home page article id can be ‘homepage’.
Note:¶
Before calling the init and load methods, please make sure the piStats library has loaded. The best place to include the library is the ‘head’ section and the methods can be called anywhere after that, for example in the footer.
<script>
var site_lang=<language>;
var site_story_id=<story_id>;
$.getScript( "http://dlvkf5067xruv.cloudfront.net/library_analytics.min.js",function( data, status, jqxhr ) {
});
</script>
piStats.init(<property-id>);
piStats.load("Page Load");
Another way to do this is to combine the calls, and call the init and load methods on the library callback, as follows:
<script>
var site_lang=<language>;
var site_story_id=<story_id>;
$.getScript( "http://dlvkf5067xruv.cloudfront.net/library_analytics.min.js",function( data, status, jqxhr ) {
var site_story_id = site_story_id;
piStats.init(<property-id>);
piStats.load('PageLoad');
});
</script>
Android¶
- Add the following permissions:
<uses-permission android:name="android.permission.ACCESS_COARSE_LOCATION"/>
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
<uses-permission android:name="android.permission.LOCATION"/>
<uses-permission android:name="android.permission.INTERNET"/>
- Add piStats SDK to your app:
- In Android studio ‘File > New > New Module’ → Select ‘Import .jar/.aar’ package
- import piStats.aar
- In build.gradle add:
compile project(':pistats')
- Add the following in ‘onCreate()’ of the application
PiStats.getInstance().init(this, <PropertyId>);
- Registration :
public class PistatsRegistrationReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent)
{
Event event = new Event();
event.setPropertyId(<propertyId>);
if (!TextUtils.isEmpty(<Language>))
event.setLanguage(<Language>);
PiStats.getInstance().registrationEvent(event);
}
}
- Register the broadcast receiver in manifest
<receiver
android:name=".PistatsRegistrationReceiver"
android:enabled="true"
android:exported="true"
tools:ignore="ExportedReceiver">
<intent-filter>
<action android:name="com.pistats.registration.action"/>
</intent-filter>
</receiver>
- Load: This event is used to track all the different pages/screens a user visits. This would be the most frequently used event in the app. Not only does this event keep track of user browsing history but also combines referral information as well.
Note: For details about referral parameters please refer to: Referral Analytics
LoadEvent event = new LoadEvent();
event.setEventName("PageLoad");
event.setPropertyId(<PropertyId>);
event.setLangauageUser(<Language>);
event.setContentId(<contentId>);
event.setReferrerType(<ReferrerType>);
event.setReferrerOrigin(<ReferrerOrigin>);
event.setReferrerMedium(<ReferrerMedium>);
event.setReferrerIndex(<ReferrerIndex>);
PiStats.getInstance().pageLoadEvent(event);
iOS - ObjectiveC¶
- Add the following permissions in the app’s plist file:
- Location
- Add piStats SDK to the X-code project
- Add Firebase SDK: Please follow the instructons in the link below: https://firebase.google.com/docs/cloud-messaging/ios/client
- Import piStats in AppDelegate.m
import <pistats/PistatsManage.h>
- Initialize piStats in application:didFinishLaunchingWithOptions
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[[PistatsManage getInstance]initWithProperty:PiStatsPropertyid];
}
- Implement observer: Add kPiStatsObserverNotification in application:didFinishLaunchingWithOptions
(BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[PistatsManage getInstance];
[[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(pistatObserverCall:)
name:kPiStatsObserverNotification object:nil];
}
(void)pistatObserverCall:(NSNotification*)notification
{
[self registrationCallForPistats];
}
After piStats SDK has been initialized we need to implement:
- Registration :
- After we have received the FCM registration token we need to register the device with piStats for push notification.
NewEvent *event = [[NewEvent alloc]init];
event.Language = @“Language name”,
event.PropertyId = PiStatsPropertyid;
event.deviceUDID = @“device UDID”;
[[PistatsManage getInstance]registerForDevice:PiStatsPropertyid WithEvent:event];
- Load: This event is used to track all the different pages/screens a user visits. This would be the most frequently used event in the app. Not only does this event keep track of user browsing history but also combines referral information as well.
Note: For details about referral parameters please refer to: Referral Analytics
NewEvent *event = [[NewEvent alloc]init];
event.EventName = @"PageLoad";
event.Language = @“Language name”;
event.ReferrerOrigin = @"internal";
event.ReferrerMedium = @"page";
event.ReferrerType = @“type”;
event.EventTimestamp = @“Timestamp” /* ISO date and time formate
event.PropertyId = PiStatsPropertyid;
event.ContentID = @“ContentID”;
event.deviceUDID = @“device UDID”;
[[PistatsManage getInstance]loadviewController:self WithEvent:event];
iOS - Swift¶
- Add the following permissions in the app’s plist file:
- Location
- Notifications
- Add piStats SDK to the X-code project and import two files in project bridging header
#import <pistats/PistatsManage.h>
#import <pistats/NewEvent.h>
- Add Firebase SDK: Please follow the instructons in the link below: https://firebase.google.com/docs/cloud-messaging/ios/client
- Import piStats in AppDelegate
import pistats
- Initialize piStats in application:didFinishLaunchingWithOptions
func application(_ application: UIApplication, didFinishLaunchingWithOptions launchOptions: [UIApplicationLaunchOptionsKey: Any]?) -> Bool
{
PistasManage.getInstance()(property:PiStatsPropertyid)
}
}
- Implement observer: Add kPiStatsObserverNotification in application:didFinishLaunchingWithOptions
NotificationCenter.default.addObserver(self, selector: Selector(("pistatObserverCall:")), name: NSNotification.Name.piStatsObserver, object: nil)
func pistatObserverCall(_ notification: Notification) {
self.registrationCallForPistats()
self.subscribeCallForPistats()
}
After piStats SDK has been initialized we can track the following type of events:
- Registration :
- After we have received the FCM registration token we need to register the device with piStats for push notification.
if let fcmTokenDefaultValue = userDefault.value(forKey:pistatsFCMToken)
{
fcmTokenDefaultValue = deviceTokenValue as! String
}
let notifnEvent = NewEvent()
notifnEvent.language = currentLanguage()
notifnEvent.fcmToken = fcmToken /* Firebase token Mandatory */
if let deviceTokenValue = userDefault.value(forKey:pistatsDeviceToken)
{
notifnEvent.deviceUDID = deviceTokenValue as! String
}
notifnEvent.proprtyId = pistatsPropertyId
notifnEvent.eventTimestamp = getTimeandDateInISO()
(PistatsManage.getInstance() as AnyObject).register(forDevice: notifnEvent)
- Load: This event is used to track all the different pages/screens a user visits. This would be the most frequently used event in the app. Not only does this event keep track of user browsing history but also combines referral information as well.
let event = NewEvent()
event.eventTimestamp = currentFormattedDate()
event.language = currentLanguage()
event.proprtyId = pistatsPropertyId
event.referrerOrigin = RefferOrigin.HOME
event.referrerMedium = sectionName
event.contentID = newsID
(PistatsManage.getInstance() as AnyObject).loadviewController(self, with:event)